package com.liyunhan.SortAlgorithm;

import java.util.ArrayList;

/**
 * @Description: 算法模板式
 * @Author: Liyunhan
 * @Date: 2021/10/3 21:08
 */
public abstract class AlgorithmAbs {
    ArrayList<Double> arrayList = new ArrayList<>();

    /**
     * 不提供无参构造方法, 算法必须传入待排序序列(要求为浮点型)
     * @param arrayList
     */
    public AlgorithmAbs(ArrayList<Double> arrayList) {
        //为了保留原始序列
        this.arrayList.addAll(arrayList);
    }

    /**
     * 算法计时器开始
     * @return
     */
    public final double startClock(){
        return System.currentTimeMillis();
    }

    /**
     * 算法计时器结束
     * @return
     */
    public final double stopClock(){
        return System.currentTimeMillis();
    }

    /**
     * 算法执行
     * @return
     */
    public abstract void executeAlgorithm(int...ints);

    /**
     * 模板方法
     * @return
     */
    public final double start(int...ints){
        //算法开始
        double start = startClock();

        executeAlgorithm(ints);

        //算法结束
        double end = stopClock();

        //算法时间
        double exTime = (end - start)/1000;
        return exTime;
    }


    /**
     * getter and setter
     */

    public ArrayList<Double> getArrayList() {
        return arrayList;
    }

    public void setArrayList(ArrayList<Double> arrayList) {
        this.arrayList = arrayList;
    }
}
